package com.macaline.service.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macaline.bean.PageVo;
import com.macaline.mapper.BaseMapper;

/**
 * Service层通用的方法集
 */
public abstract class BaseService<T> {

    public abstract BaseMapper<T> getMapper();


    /**
     * 通过id获取
     * @param id
     * @return
     */
    public T getById(String id){
        return getMapper().selectById(id);
    }

    /**
     *  获取列表
     * @param vo
     * @return
     */
    public IPage<T> getList(PageVo vo) {
        QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
        vo.getParam().forEach((key, val) -> {
            queryWrapper.eq((String) key, val);
        });
        return getMapper().selectPage(new Page<>(vo.getCurrent(), 10), queryWrapper);
    }

}
